package com.one.group.admin.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.one.group.admin.mapper.MaintenanceRecordMapper;
import com.one.group.model.dto.MaintenanceRecordAddDto;
import com.one.group.model.dto.MaintenanceRecordQueryDto;
import com.one.group.model.dto.MaintenanceRecordUpdateDto;
import com.one.group.model.entity.MaintenanceRecord;
import com.one.group.model.vo.MaintenanceRecordVo;
import com.one.group.service.MaintenanceRecordService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * {@code @Create:}  2025-09-28  14 : 52
 * {@code @Author:} Cherry
 * {@code @ToUser:} 凡是发生,皆有利于我。
 * ------------------------------------
 * {@code @note:}
 */

@SuppressWarnings({"all"})
@Service
public class MaintenanceRecordServiceImpl extends ServiceImpl<MaintenanceRecordMapper, MaintenanceRecord> implements MaintenanceRecordService {
    @Resource
    private MaintenanceRecordMapper maintenanceRecordMapper;

    @Override
    public void addSpMaintenanceRecord(MaintenanceRecordAddDto addDto) {
        MaintenanceRecord maintenanceRecord = MaintenanceRecord.builder().tenantId(Convert.toLong(StpUtil.getExtra("adminTenantId:"))).build();
        maintenanceRecord.setMaintenanceOrderNumber(UUID.randomUUID().toString() + System.currentTimeMillis());
        BeanUtil.copyProperties(addDto, maintenanceRecord, false);
        maintenanceRecordMapper.insertSelective(maintenanceRecord);
    }

    @Override
    public List<MaintenanceRecordVo> listSpMaintenanceRecords(MaintenanceRecordQueryDto queryDto) {
        queryDto.setTenantId(Convert.toLong(StpUtil.getExtra("tenant_id")));
        List<MaintenanceRecordVo> maintenanceRecordVoList = maintenanceRecordMapper.selectList(queryDto);
        return maintenanceRecordVoList;
    }

    @Override
    public void updateSpMaintenanceRecord(MaintenanceRecordUpdateDto updateDto) {
        MaintenanceRecord maintenanceRecord = MaintenanceRecord.builder().build();
        BeanUtil.copyProperties(updateDto, maintenanceRecord);
        maintenanceRecordMapper.update(maintenanceRecord);
    }

    @Override
    public void batchDeleteSpMaintenanceRecords(List<Long> ids) {

        maintenanceRecordMapper.deleteBatchByIds(ids);
    }

    @Override
    public void deleteById(Long id) {

        maintenanceRecordMapper.deleteById(id);
    }

}
